from sklearn.model_selection import KFold, train_test_split
import numpy as np

class Base:
    def __init__(self):
        self.y_true = []
        self.y_pred = []
        self.user_true = []
        self.user_pred = []
        self.users = []

    def save_pred_true(self, y_pred, y_true):
        self.y_pred.extend(y_pred)
        self.y_true.extend(y_true)
        self.user_pred.extend(y_pred)
        self.user_true.extend(y_true)

    def print_pred_true(self, user=True):
        print('#################################################################')
        print('预测值:', self.y_pred)
        print('真实值:', self.y_true)
        pred = np.array(self.y_pred)
        true = np.array(self.y_true)
        ratio = np.sum(pred == true) / pred.shape[0]
        print('准确率',ratio)
        with open('a.txt', 'a') as f:
            f.write(str(ratio) + '\n')
        if user:
            self.users.append([self.user_pred, self.user_true])
            self.user_pred = []
            self.user_true = []
        print('所有用户', self.users)

